clc 
close all
clear all
%%PRKS
prks70 = importdata('PRKS70_throughput_rd1.txt');
prks80 = importdata('PRKS80_throughput_rd1.txt');
prks90 = importdata('PRKS90_throughput_rd1.txt');
prks95 = importdata('PRKS95_throughput_rd1.txt');

rid70 = importdata('RID70_throughput_rd1.txt');
rid80 = importdata('RID80_throughput_rd1.txt');
rid90 = importdata('RID90_throughput_rd1.txt');
rid95 = importdata('RID95_throughput_rd1.txt');

cmac70 = importdata('CMAC70_throughput_rd1.txt');
cmac80 = importdata('CMAC80_throughput_rd1.txt');
cmac90 = importdata('CMAC90_throughput_rd1.txt');
cmac95 = importdata('CMAC95_throughput_rd1.txt');

scream = importdata('SCREAM_throughput_rd1.txt');
csma = importdata('CSMA_throughput_rd1.txt');
rtscts = importdata('RTSCTS_throughput_rd1.txt');

ALPHA=0.05;

MEAN = zeros(4,6);
Error_MEAN = zeros(4,6);
MEAN(1,1) = mean(prks70);
MEAN(1,2) = mean(csma);
MEAN(1,3) = mean(rtscts);
MEAN(1,4) = mean(rid70);
MEAN(1,5) = mean(cmac70);
MEAN(1,6) = mean(scream);
Error_MEAN(1,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks70) / sqrt(size(prks70, 1));
Error_MEAN(1,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma) / sqrt(size(csma, 1));
Error_MEAN(1,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts) / sqrt(size(rtscts, 1));
Error_MEAN(1,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(rid70) / sqrt(size(rid70, 1));
Error_MEAN(1,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(cmac70) / sqrt(size(cmac70, 1));
Error_MEAN(1,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(scream) / sqrt(size(scream, 1));

MEAN(2,1) = mean(prks80);
MEAN(2,2) = mean(csma);
MEAN(2,3) = mean(rtscts);
MEAN(2,4) = mean(rid80);
MEAN(2,5) = mean(cmac80);
MEAN(2,6) = mean(scream);
Error_MEAN(2,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks80) / sqrt(size(prks80, 1));
Error_MEAN(2,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma) / sqrt(size(csma, 1));
Error_MEAN(2,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts) / sqrt(size(rtscts, 1));
Error_MEAN(2,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(rid80) / sqrt(size(rid80, 1));
Error_MEAN(2,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(cmac80) / sqrt(size(cmac80, 1));
Error_MEAN(2,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(scream) / sqrt(size(scream, 1));

MEAN(3,1) = mean(prks90);
MEAN(3,2) = mean(csma);
MEAN(3,3) = mean(rtscts);
MEAN(3,4) = mean(rid90);
MEAN(3,5) = mean(cmac90);
MEAN(3,6) = mean(scream);
Error_MEAN(3,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks90) / sqrt(size(prks90, 1));
Error_MEAN(3,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma) / sqrt(size(csma, 1));
Error_MEAN(3,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts) / sqrt(size(rtscts, 1));
Error_MEAN(3,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(rid90) / sqrt(size(rid90, 1));
Error_MEAN(3,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(cmac90) / sqrt(size(cmac90, 1));
Error_MEAN(3,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(scream) / sqrt(size(scream, 1));

MEAN(4,1) = mean(prks95);
MEAN(4,2) = mean(csma);
MEAN(4,3) = mean(rtscts);
MEAN(4,4) = mean(rid95);
MEAN(4,5) = mean(cmac95);
MEAN(4,6) = mean(scream);
Error_MEAN(4,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks95) / sqrt(size(prks95, 1));
Error_MEAN(4,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma) / sqrt(size(csma, 1));
Error_MEAN(4,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts) / sqrt(size(rtscts, 1));
Error_MEAN(4,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(rid95) / sqrt(size(rid95, 1));
Error_MEAN(4,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(cmac95) / sqrt(size(cmac95, 1));
Error_MEAN(4,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(scream) / sqrt(size(scream, 1));


figure;
handle = barweb(MEAN, Error_MEAN,1, ['70';'80';'90';'95'], [], ['PDR requirement(%)'], ['Mean throughput'], jet);
handle.legend =legend ('PRKS','CSMA','RTS-CTS', 'RIDB','CMAC','SCREAM','orientation','horizontal');
set(gca,'fontsize',36);
box on
maximize ();

[im_hatch, colorlist]=applyhatch_pluscolor(gcf, '/-\xkc',1,[1 1 1 1 0 1],[],[],5,10);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%FOR THROUGHPUT TYPE_II%%%%%%%%%%%%%%%%%%%%%%%%%%
%{
csma70 = importdata('csma70_throughput.txt');
csma80 = importdata('csma80_throughput.txt');
csma90 = importdata('csma90_throughput.txt');
csma95 = importdata('csma95_throughput.txt');

rtscts70 = importdata('rtscts70_throughput.txt');
rtscts80 = importdata('rtscts80_throughput.txt');
rtscts90 = importdata('rtscts90_throughput.txt');
rtscts95 = importdata('rtscts95_throughput.txt');

ALPHA=0.05;

MEAN = zeros(4,3);
Error_MEAN = zeros(4,3);

MEAN(1,1) = mean(prks70);
MEAN(1,2) = mean(csma70);
MEAN(1,3) = mean(rtscts70);
Error_MEAN(1,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks70) / sqrt(size(prks70, 1));
Error_MEAN(1,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma70) / sqrt(size(csma70, 1));
Error_MEAN(1,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts70) / sqrt(size(rtscts70, 1));

MEAN(2,1) = mean(prks80);
MEAN(2,2) = mean(csma80);
MEAN(2,3) = mean(rtscts80);
Error_MEAN(2,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks80) / sqrt(size(prks80, 1));
Error_MEAN(2,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma80) / sqrt(size(csma80, 1));
Error_MEAN(2,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts80) / sqrt(size(rtscts80, 1));

MEAN(3,1) = mean(prks90);
MEAN(3,2) = mean(csma90);
MEAN(3,3) = mean(rtscts90);
Error_MEAN(3,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks90) / sqrt(size(prks90, 1));
Error_MEAN(3,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma90) / sqrt(size(csma90, 1));
Error_MEAN(3,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts90) / sqrt(size(rtscts90, 1));

MEAN(4,1) = mean(prks95);
MEAN(4,2) = mean(csma95);
MEAN(4,3) = mean(rtscts95);
Error_MEAN(4,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks95) / sqrt(size(prks95, 1));
Error_MEAN(4,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma95) / sqrt(size(csma95, 1));
Error_MEAN(4,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts95) / sqrt(size(rtscts95, 1));

figure;
handle = barweb(MEAN, Error_MEAN,1, ['70%';'80%';'90%';'95%'], [], ['PDR requirement'], ['Mean throughput (number of packets per slot)'], jet);
handle.legend =legend ('PRKS','CSMA','RTS-CTS','orientation','horizontal');
set(gca,'fontsize',60);
box on
maximize ();
%}
